";
if($_FILES['Photo']['error'][$i] > 0) {
echo "檔案名稱:" . $_FILES['Photo']['name'][$i] . "
";
switch ($_FILES['Photo']['error'][$i]) {
case 1: die("大小超出php.ini 限制");
case 2: die("大小超出MAX_FILE_SIZE限制");
case 3: die("僅被部份上傳");
case 4: die("未被上傳");
}
}
$destDir = "photos";
if(!is_dir($destDir) || !is_writeable($destDir))
die("目錄不存在或無法寫入");
// 檔案格式判斷
$checkExt = getimagesize($_FILES['Photo']['tmp_name'][$i]);
if ($checkExt[2] == NULL)
die("檔案格式不符");
// 指定副檔名
switch($checkExt[2]) {
case 1: $Ext = "gif"; break;
case 2: $Ext = "jpg"; break;
case 3: $Ext = "png"; break;
}
// 檔案命名
$Name = date("Ymd") . "_" . substr(md5(uniqid(rand())),0,5) . "." . $Ext;
// 複製暫存檔
move_uploaded_file($_FILES['Photo']['tmp_name'][$i], $destDir . "/" . $Name );
// 判斷是否縮圖
if ($_POST['checkResize'] == "checkbox") {
$src = $destDir . "/" . $Name;
$dest = $src;
$destW = $_POST['px'];
$destH = $destW;
imagesResize($src, $dest, $destW, $destH);
}
// 預覽圖
$src = $destDir . "/" . $Name;
$dest = $destDir . "/thum/" . "thum_" . $Name;
$destW = 100;
$destH = 100;
//echo "縮圖名稱: " . $dest;
imagesResize($src, $dest, $destW, $destH);
$insertSQL = sprintf("INSERT INTO album (Name, Name_thum, `Comment`) VALUES (%s, %s, %s)",
GetSQLValueString($src, "text"),
GetSQLValueString($dest, "text"),
GetSQLValueString($_POST['Comment'][$i], "text"));
mysql_select_db($database_conn_album, $conn_album);
$Result1 = mysql_query($insertSQL, $conn_album) or die(mysql_error());
}
}
//$insertGoTo = "upload.php";
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>